import request from '@/utils/request'

// 查询artilce列表
export function listArticle(query) {
  return request({
    url: '/article/article/list',
    method: 'get',
    params: query
  })
}

export function uploadFile(id, formData) {
  return request({
    url: '/article/article/filePath/' + id,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}
export function uploadAppval(id, formData) {
  return request({
    url: '/article/article/appvalPath/' + id,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 附件上传
export function uploadAttachment(id, formData) {
  return request({
    url: '/article/article/attachment/' + id,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 文章内容图片上传
export function uploadContentImage(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/article/article/contentImage',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}


export function uploadAttachs(data) {
  return request({
    url: '/article/article/adds',
    method: 'get',
    params: data
  })
}

// 查询artilce详细
export function getArticle(articleId) {
  return request({
    url: '/article/article/' + articleId,
    method: 'get'
  })
}

// 新增artilce
export function addArticle( articleName,data) {
  return request({
    url: '/article/article?articleName='+articleName,
    method: 'post',
    data: data
  })
}

// 修改artilce
export function updateArticle(articleName,data) {
  return request({
    url: '/article/article?articleName='+articleName,
    method: 'put',
    data: data
  })
}

// 删除artilce
export function delArticle(articleId) {
  return request({
    url: '/article/article/' + articleId,
    method: 'delete'
  })
}

//逻辑删除article
export function logicDeleteArticle(articleId){
  return request({
    url: "/article/article/logicDelete/"+articleId,
    method: "post"
  })
}

//隐藏article
export function hideArticle(articleId){
  return request({
    url: "/article/article/hide/"+articleId,
    method: "put"
  })
}

//显示article
export function showArticle(articleId){
  return request({
    url: "/article/article/show/"+articleId,
    method: "put"
  })
}


//批量隐藏
export function batchHideArticle(articleIds){
  return request({
    url: "/article/article/hideBatch",
    method: "put",
    data: articleIds
  })
}

//批量显示
export function batchShowArticle(articleIds){
  return request({
    url: "/article/article/showBatch",
    method: "put",
    data: articleIds
  })
}

// 按条件批量隐藏文章
export function batchHideArticleByCondition(params){
  return request({
    url: "/article/article/batchHideByCondition",
    method: "put",
    params: params
  })
}

// 按条件批量显示文章
export function batchShowArticleByCondition(params){
  return request({
    url: "/article/article/batchShowByCondition",
    method: "put",
    params: params
  })
}

// 保存草稿
export function saveDraft(data) {
  return request({
    url: '/article/draft',
    method: 'post',
    data: data
  })
}

// 更新草稿
export function updateDraft(data) {
  return request({
    url: '/article/draft',
    method: 'put',
    data: data
  })
}

// 发布草稿
export function publishDraft(articleId) {
  return request({
    url: '/article/draft/publish/' + articleId,
    method: 'post'
  })
}

// 查询草稿列表
export function listDraft(query) {
  return request({
    url: '/article/draft/list',
    method: 'get',
    params: query
  })
}


